<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/xizhongren8980/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/xizhongren8980/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/xizhongren8980/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/xizhongren8980/images/logo.svg" color="#222">

<link rel="stylesheet" href="/xizhongren8980/css/main.css">


<link rel="stylesheet" href="/xizhongren8980/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/xizhongren8980/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="今天跟着B站UP主做的飘落动画，虽然奇丑无比，但是至少实现了功能。哈哈 参考视频：https:&#x2F;&#x2F;www.bilibili.com&#x2F;video&#x2F;av61008317&#x2F; 视频来源：B站博主   Aimls">
<meta property="og:type" content="article">
<meta property="og:title" content="Javafx制作飘落动画">
<meta property="og:url" content="https://gitee.com/xizhongren8980/xizhongren8980.git/2020/03/06/%E9%A3%98%E8%90%BD%E5%8A%A8%E7%94%BB/index.html">
<meta property="og:site_name" content="一杯茶一包烟，一个BUG改一天">
<meta property="og:description" content="今天跟着B站UP主做的飘落动画，虽然奇丑无比，但是至少实现了功能。哈哈 参考视频：https:&#x2F;&#x2F;www.bilibili.com&#x2F;video&#x2F;av61008317&#x2F; 视频来源：B站博主   Aimls">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://github.com/MisterTian8980/PictureOfMyHexoBlog/raw/master/images/Javafx%E9%A3%98%E8%90%BD%E5%8A%A8%E7%94%BB/img2.png">
<meta property="og:image" content="https://github.com/MisterTian8980/PictureOfMyHexoBlog/raw/master/images/Javafx%E9%A3%98%E8%90%BD%E5%8A%A8%E7%94%BB/img1.png">
<meta property="article:published_time" content="2020-03-06T11:50:44.929Z">
<meta property="article:modified_time" content="2020-02-07T05:36:10.826Z">
<meta property="article:author" content="MisterTian">
<meta property="article:tag" content="Javafx">
<meta property="article:tag" content="动画">
<meta property="article:tag" content="飘落">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://github.com/MisterTian8980/PictureOfMyHexoBlog/raw/master/images/Javafx%E9%A3%98%E8%90%BD%E5%8A%A8%E7%94%BB/img2.png">

<link rel="canonical" href="https://gitee.com/xizhongren8980/xizhongren8980.git/2020/03/06/%E9%A3%98%E8%90%BD%E5%8A%A8%E7%94%BB/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Javafx制作飘落动画 | 一杯茶一包烟，一个BUG改一天</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/xizhongren8980/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">一杯茶一包烟，一个BUG改一天</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">收藏永不停止，学习永不开始</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/xizhongren8980/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/xizhongren8980/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/xizhongren8980/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/xizhongren8980/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/xizhongren8980/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/xizhongren8980/xizhongren8980.git/2020/03/06/%E9%A3%98%E8%90%BD%E5%8A%A8%E7%94%BB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/xizhongren8980/images/head.jpg">
      <meta itemprop="name" content="MisterTian">
      <meta itemprop="description" content="一个小菜鸟">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一杯茶一包烟，一个BUG改一天">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Javafx制作飘落动画
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-03-06 19:50:44" itemprop="dateCreated datePublished" datetime="2020-03-06T19:50:44+08:00">2020-03-06</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-02-07 13:36:10" itemprop="dateModified" datetime="2020-02-07T13:36:10+08:00">2020-02-07</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>今天跟着B站UP主做的飘落动画，虽然奇丑无比，但是至少实现了功能。哈哈</p>
<p>参考视频：<a href="https://www.bilibili.com/video/av61008317/" target="_blank" rel="noopener">https://www.bilibili.com/video/av61008317/</a></p>
<p>视频来源：B站博主   Aimls<a id="more"></a></p>
<p>这位博主的Javafx系列视频做的很不错，讲的也很细，只可惜看的人太少了。</p>
<h3 id="源代码"><a href="#源代码" class="headerlink" title="源代码"></a>源代码</h3><pre>
package Test;

import Game_pintu.Music;
import javafx.animation.*;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.net.URL;
import java.util.ArrayList;
import java.util.Random;
import java.util.function.Consumer;

/**
 * @Auther: 戏中人
 * @Date: 2020/2/5 12:40
 * @Description:
 */
public class Flower extends Application {

    ArrayList<ParallelTransition> list = new ArrayList<>();//并行动画链表

    public static void main(String[] args) {
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) throws Exception {

        String s1 = Music.class.getResource("./Twinbed - Trouble I'm In.mp3").toString();
        Media media = new Media(s1);
        MediaPlayer mp = new MediaPlayer(media);//背景音乐

        StackPane sp = new StackPane();

        ImageView bg = new ImageView("./Game_pintu/img1.png");//背景图片
        bg.setFitWidth(1920);
        bg.setFitHeight(1080);

        AnchorPane root = new AnchorPane();
        root.setStyle("-fx-background-color: #ffffff");
        Scene scene = new Scene(root);

        primaryStage.setScene(scene);
        primaryStage.centerOnScreen();
        primaryStage.setFullScreen(true);
        primaryStage.setFullScreenExitHint("");
        primaryStage.show();


        root.getChildren().addAll(sp);
        Node flowerView = getView(33, (int) scene.getWidth(), (int) scene.getHeight(), 2500);
        sp.getChildren().addAll(bg,flowerView);

        KeyCombination key = new KeyCodeCombination(KeyCode.Y, KeyCombination.CONTROL_DOWN);//快捷键ctrl+y
        scene.getAccelerators().put(key, new Runnable() {
            @Override
            public void run() {
                list.forEach(new Consumer<ParallelTransition>() {
                    @Override
                    public void accept(ParallelTransition t) {
                        t.play();
                    }
                });
                mp.play();
            }
        });
    }

    public Node getView(int number, int w, int h, int z) {
        int location_x;
        int location_y;
        int location_z;

        Random random = new Random();

        ArrayList<ImageView> imagelist = new ArrayList<>();

        for (int i = 0; i < number; i++) {
            ImageView iv = new ImageView("Test/Ak.png");
            iv.setFitWidth(100);
            iv.setFitHeight(100);
            iv.setPreserveRatio(true);//保持宽高比

            if (random.nextBoolean() == true) {
                location_x = random.nextInt(w) + random.nextInt(300) + 300;

            }else {
                location_x = random.nextInt(w) - random.nextInt(300) - 300;
            }

            location_y = random.nextInt(50);
            location_z = random.nextInt(z);

            iv.setTranslateX(location_x);
            iv.setTranslateY(location_y);
            iv.setTranslateZ(location_z);

            iv.setOpacity(0);//初始化的时候为透明
            imagelist.add(iv);
        }
        AnchorPane ap = new AnchorPane();
        ap.setStyle("-fx-background-color: #ffb6c100");
        ap.getChildren().addAll(imagelist);
        SubScene subScene = new SubScene(ap, w, h, true, SceneAntialiasing.BALANCED);
        PerspectiveCamera camera = new PerspectiveCamera();
        subScene.setCamera(camera);

        imagelist.forEach(new Consumer<ImageView>() {
            @Override
            public void accept(ImageView imageView) {
                double time = random.nextDouble() * 10 + 5;
                TranslateTransition tt = new TranslateTransition(Duration.seconds(time));
                tt.setFromX(imageView.getTranslateX());
                tt.setFromY(imageView.getTranslateY());
                tt.setByX(400);//增量
                tt.setByY(1300);//增量

                RotateTransition rt = new RotateTransition(Duration.seconds(time));//旋转动画
                rt.setFromAngle(0);
                rt.setToAngle(360);

                FadeTransition ft1 = new FadeTransition(Duration.seconds(time/2));
                ft1.setFromValue(0);
                ft1.setToValue(1);

                FadeTransition ft2 = new FadeTransition(Duration.seconds(3));
                ft2.setFromValue(1);
                ft2.setToValue(0);

                SequentialTransition st = new SequentialTransition();//串行动画
                st.getChildren().addAll(ft1, ft2);

                ParallelTransition pt = new ParallelTransition();//并行动画
                pt.setNode(imageView);
                pt.getChildren().addAll(tt,rt,st);
                pt.setCycleCount(Animation.INDEFINITE);
                list.add(pt);//方便在外部进行播放控制
            }
        });
        return subScene;
    }
}

</pre>


<p><strong>博主的效果截图</strong></p>
<p><img src="https://github.com/MisterTian8980/PictureOfMyHexoBlog/raw/master/images/Javafx%E9%A3%98%E8%90%BD%E5%8A%A8%E7%94%BB/img2.png" alt=""></p>
<p><strong>自己的截图</strong></p>
<p><img src="https://github.com/MisterTian8980/PictureOfMyHexoBlog/raw/master/images/Javafx%E9%A3%98%E8%90%BD%E5%8A%A8%E7%94%BB/img1.png" alt=""></p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/xizhongren8980/tags/Javafx/" rel="tag"># Javafx</a>
              <a href="/xizhongren8980/tags/%E5%8A%A8%E7%94%BB/" rel="tag"># 动画</a>
              <a href="/xizhongren8980/tags/%E9%A3%98%E8%90%BD/" rel="tag"># 飘落</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/xizhongren8980/2020/03/06/Win%E4%B8%8BJava%E7%9A%84JDK%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE/" rel="prev" title="Win10下Java的JDK环境配置">
      <i class="fa fa-chevron-left"></i> Win10下Java的JDK环境配置
    </a></div>
      <div class="post-nav-item">
    <a href="/xizhongren8980/2020/03/06/%E5%A4%A7%E6%88%98%E7%97%85%E6%AF%92%E6%90%9E%E7%AC%91%E5%8A%A8%E7%94%BB/" rel="next" title="编码贺新年">
      编码贺新年 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#源代码"><span class="nav-number">1.</span> <span class="nav-text">源代码</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="MisterTian"
      src="/xizhongren8980/images/head.jpg">
  <p class="site-author-name" itemprop="name">MisterTian</p>
  <div class="site-description" itemprop="description">一个小菜鸟</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/xizhongren8980/archives/">
        
          <span class="site-state-item-count">57</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/xizhongren8980/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/xizhongren8980/tags/">
          
        <span class="site-state-item-count">101</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://mistertian8980.github.io/" title="https:&#x2F;&#x2F;mistertian8980.github.io&#x2F;" rel="noopener" target="_blank">Github博客</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">MisterTian</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script size="300" alpha="0.6" zIndex="-1" src="/xizhongren8980/lib/canvas-ribbon/canvas-ribbon.js"></script>
  <script src="/xizhongren8980/lib/anime.min.js"></script>
  <script src="/xizhongren8980/lib/velocity/velocity.min.js"></script>
  <script src="/xizhongren8980/lib/velocity/velocity.ui.min.js"></script>

<script src="/xizhongren8980/js/utils.js"></script>

<script src="/xizhongren8980/js/motion.js"></script>


<script src="/xizhongren8980/js/schemes/pisces.js"></script>


<script src="/xizhongren8980/js/next-boot.js"></script>


  <script defer src="//cdn.jsdelivr.net/gh/theme-next/theme-next-three@1/three.min.js"></script>
    <script defer src="//cdn.jsdelivr.net/gh/theme-next/theme-next-three@1/canvas_lines.min.js"></script>


  




  
<script src="/xizhongren8980/js/local-search.js"></script>













  

  

</body>
</html>
